﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ObjectTransposeApi;

namespace ObjectTransposeApiSystemTest.TestFixture
{
    [TestFixture]
    public class ToValueDefaultFixture
    {
        public class NullStructure
        {
            public object Values
            {
                get { return null; }
                set { /* dso nothing */; }
            }
        }

        public class ValueStructure
        {
            public object Value { get; set; }
        }

        public class FirstChildStructure
        {
            public string Value { get; set; }
        }

        public class SecondChildStructure
        {
            private SecondChildStructure() 
            {
            }

            public string Value { get; set; }
        }

        public class ParentStructure
        {
            public FirstChildStructure FirstChildStructure { get; set; }
            public SecondChildStructure SecondChildStructure { get; set; }
        }

        [Test]
        public void ConstructorTest()
        {
            var sources = new
            {
                FirstChildStructure = new { Value = "test" }
            };

            ParentStructure parentStructure = ObjectToValue.Copy<ParentStructure>(sources);

            // make sure the field was set
            Assert.IsNotNull(parentStructure.FirstChildStructure);
            Assert.AreEqual(parentStructure.FirstChildStructure.Value, "test");
        }

        [Test]
        public void NoConstructorTest()
        {
            var sources = new
            {
                SecondChildStructure = new { Value = "test" }
            };

            ParentStructure parentStructure = ObjectToValue.Copy<ParentStructure>(sources);

            // make sure the field was set
            Assert.IsNull(parentStructure.SecondChildStructure);
        }
    }
}
